<template>
  <div class="person" v-loading="loading">
    <template v-if="list.length > 0" v-for="item in list" :key="item">
      <div class="person-item" @click="showPersonDetail(item)">
        <div class="person-item-left">
          <div class="person-item-left-name">
            <span
              class="person-item-left-name-text"
              :class="{
                'text-yellow': item.isLeader === '1',
                'text-green': item.isSpecial === '1'
              }"
            >
              {{ item.name }}
            </span>
            <span v-if="item.workType">&nbsp;&nbsp;·&nbsp;&nbsp;</span>
            <span>{{ item.workType }}</span>
          </div>
          <div class="person-item-left-station">{{ item.jzName }}</div>
          <div class="person-item-left-time">入井{{ item.inTimeStr }}</div>
          <div class="person-item-left-entry-time">{{ item.entryDate || '--' }} 入井</div>
        </div>
        <div class="person-item-right">
          <div class="history-btn" @click.stop>
            <i class="iconfont icon-huifang"></i>
            轨迹
          </div>
          <img
            v-if="item.archivesUrl"
            class="person-item-right--image"
            :src="`${BASE_URL}/system/archives/download/${item.archivesUrl}`"
          />
          <img v-else class="person-item-right--image" src="@/assets/images/people.svg" />
        </div>
      </div>
    </template>
    <b-empty v-else></b-empty>
  </div>
</template>
<script setup lang="ts">
import bEmpty from '@/components/b-empty.vue'
import { ref, onMounted, onUnmounted } from 'vue'
import { getPersonList } from '@/api/person'

const props = defineProps({
  params: {
    type: Object,
    default: () => {}
  }
})

const interval = ref(null)
onMounted(async () => {
  await getPersonListFun()

  interval.value = setInterval(async () => {
    await getPersonListFun()
  }, 60000)
})

onUnmounted(() => {
  clearInterval(interval.value)
})

const list = ref([])
const loading = ref(false)
async function getPersonListFun() {
  loading.value = true
  const { data } = await getPersonList({ ...props.params, pageSize: -1 })
  list.value = data.records
  loading.value = false
}
</script>
<style scoped lang="scss">
.person {
  width: 100%;
  min-width: 616px;
  display: flex;
  flex-wrap: wrap;
  gap: calc(8px * var(--scale));
  .person-item {
    background: var(--bg-color-page);
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    cursor: pointer;
    direction: ltr;
    padding: 8px;

    .person-item-left {
      text-align: left;
      flex: 1;
      display: flex;
      flex-direction: column;
      .person-item-left-name {
        font-size: 14px;
        .person-item-left-name-text {
          color: var(--el-color-primary);
          &.text-yellow {
            color: var(--el-color-warning);
          }
          &.text-green {
            color: var(--el-color-success);
          }
        }
      }
      .person-item-left-station {
        margin-top: 8px;
        font-size: 14px;
        color: var(--text-color-disabled);
      }
      .person-item-left-time {
        margin-top: 4px;
        font-size: 14px;
        color: var(--text-color-disabled);
      }
      .person-item-left-entry-time {
        margin-top: 12px;
        font-size: 12px;
        color: var(--text-color-secondary);
      }
    }
    .person-item-right {
      display: flex;
      flex-direction: column;
      align-items: center;
      margin-left: 16px;
      .history-btn {
        align-self: flex-end;
        font-size: 12px;
        color: var(--el-color-primary);
        &:hover {
          color: var(--el-color-primary-light-3);
        }
      }
      .person-item-right--image {
        height: 74px;
        background: var(--bg-color-overlay);
        margin: 4px;
        padding: 14px 10px;
        width: 100%;
        object-fit: contain;
      }
    }
  }
}
</style>
